

<script>
export default {
  name: "DeleteUser",
  data() {
    return {
      deleteUserId: "",
      deleteModal: false,
      deleteTxt: "",
    };
  },
  methods: {
    // 删除用户
    deleteUser(id = "") {
      if (id == "") {
        this.deleteTxt = "确认删除全部用户信息?";
      } else {
        this.deleteTxt = "确认删除 " + this.deleteUserId + " 用户信息?";
        this.deleteModal = true;
      }
    },
    ok() {
      this.$Spin.show({
        render: (h) => {
          return h("div", [
            h("Icon", {
              class: "demo-spin-icon-load",
              props: {
                type: "ios-loading",
                size: 18,
              },
            }),
            h("div", "Loading"),
          ]);
        },
      });
      console.log(this.deleteUserId);
      this.$axios
        .delete("users/" + this.deleteUserId)
        .then((data) => {
          this.$Spin.hide();
          if (data.data.code == 0) {
            this.$Message.success("删除成功");
          } else {
            this.$Message.error("删除失败");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // v-model
    vModel(key,e){
        this[key]=e
    }
  },
  render() {
    return (
      <div class="addUser content">
        <Form label-width={80}>
          <FormItem label="用户ID">
            <Input onInput={this.vModel.bind(this,'deleteUserId')} placeholder="请输入用户ID"></Input>
          </FormItem>
          <FormItem>
            <Button type="error" onClick={this.deleteUser.bind(this,this.deleteUserId)}>
              删除用户
            </Button>
          </FormItem>
        </Form>
        <Modal v-model={this.deleteModal} title="警告" onOn-ok={this.ok}>
          <p>{ this.deleteTxt }</p>
        </Modal>
      </div>
    );
  },
};
</script>
